package com.client.ryt.basic;

import android.app.Activity;
import android.app.Application;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by heyao on 2014/6/24.
 */
public class BaseApplication extends Application {
    static BaseApplication instance;
    public static BaseApplication getContext(){
        return instance;
    }
    private List<Activity> activityList = new LinkedList<Activity>();
    public void addActivity(Activity activity) {
        activityList.add(activity);
    }
    public static BaseApplication getInstance(){
        if(instance == null)
            instance = new BaseApplication();
        return instance;
    }

    public Activity getActivity(String packageName){
        for(int i=0;i<activityList.size();i++){
            if(activityList.get(i).getPackageName().equals(packageName))
                return activityList.get(i);
        }
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
    }

    // 遍历所有Activity并finish
    public void exit() {
        for (Activity activity : activityList) {
            activity.finish();
        }
    }
}
